Hello,
I've got what is probably a very simple question, probably something
having to do with quotes single vs. double, but the answer is
frustrating elusive, I keep getting a syntax error.
I'm trying to customize a wordpress theme a friend sent me. We're both
using apache as web server and php5, but his has got to be configed
differently than mine. The theme deals with multiple stylesheet
inclusion among other things. The original line is:
On Wed, Mar 10, 2010 at 7:15 PM, David Mehler wrote:
> Hello,
> I've got what is probably a very simple question, probably something
> having to do with quotes single vs. double, but the answer is
> frustrating elusive, I keep getting a syntax error.
> I'm trying to customize a wordpress theme a friend sent me. We're both
> using apache as web server and php5, but his has got to be configed
> differently than mine. The theme deals with multiple stylesheet
> inclusion among other things. The original line is:
>
> $styleSheets[0]["sheet"]='
> href="/wp-content/themes/theme/style/white.css" rel="stylesheet"
> type="text/css" />';
>
> That code puts the
> issue is his / is not where mine is, i'm using a virtual host and need
> a line similar to this:
>
> $styleSheets[0]["sheet"]='
> "/wp-content/themes/theme/style/white.css" rel="stylesheet"
> type="text/css" />';
>
> I've tried this with both double quotes before the
> but keep getting a parse error.
> Help appreciated.
> Thanks.
> Dave.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Nephtali: PHP web framework that functions beautifully
http://nephtaliproject.com
On Wed, 2010-03-10 at 19:33 -0500, Adam Richardson wrote:
> Try this:
>
> '
> .'/wp-content/themes/themestyle/white.css" rel="stylesheet" type="text/css"
> />';
>
> On Wed, Mar 10, 2010 at 7:15 PM, David Mehler wrote:
>
> > Hello,
> > I've got what is probably a very simple question, probably something
> > having to do with quotes single vs. double, but the answer is
> > frustrating elusive, I keep getting a syntax error.
> > I'm trying to customize a wordpress theme a friend sent me. We're both
> > using apache as web server and php5, but his has got to be configed
> > differently than mine. The theme deals with multiple stylesheet
> > inclusion among other things. The original line is:
> >
> > $styleSheets[0]["sheet"]='
> > href="/wp-content/themes/theme/style/white.css" rel="stylesheet"
> > type="text/css" />';
> >
> > That code puts the
> > issue is his / is not where mine is, i'm using a virtual host and need
> > a line similar to this:
> >
> > $styleSheets[0]["sheet"]='
> > "/wp-content/themes/theme/style/white.css" rel="stylesheet"
> > type="text/css" />';
> >
> > I've tried this with both double quotes before the
> > but keep getting a parse error.
> > Help appreciated.
> > Thanks.
> > Dave.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
You're using single quotes in your string, so you can't have PHP parse
the string for variables to extend into their corresponding values. If
you wish to do that, use either double-quoted strings or heredoc/nowdoc
syntax:
In both cases note the {} surrounding the variable. This is because PHP
needs to be told that you are trying to access an array element,
otherwise it will match only as far as $_SERVER and think that the
[ character starts regular text. This also works with object properties
and method return values:
echo "{$some_obect->some_value} and {$some_object->some_method()}";
Thanks,
Ash
http://www.ashleysheridan.co.uk
--=-tWKPGyViPBtwIkXYTMZw--
Re: php string syntax question with html
am 11.03.2010 04:06:15 von Paul M Foster
On Thu, Mar 11, 2010 at 01:17:57AM +0000, Ashley Sheridan wrote:
>
> You're using single quotes in your string, so you can't have PHP parse
> the string for variables to extend into their corresponding values. If
> you wish to do that, use either double-quoted strings or heredoc/nowdoc
> syntax:
>
> $styleSheets[0]["sheet"]="
> \"{$_SERVER['DOCUMENT_ROOT']}/wp-content/themes/theme/style/ white.css\"
> rel=\"stylesheet\" type=\"text/css\" />";
>
> or
>
> $styleSheets[0]["sheet"]= <<
>
> href="{$_SERVER['DOCUMENT_ROOT']}/wp-content/themes/theme/st yle/white.css"
> rel="stylesheet" type="text/css" />
> EOS;
>
> In both cases note the {} surrounding the variable. This is because PHP
> needs to be told that you are trying to access an array element,
> otherwise it will match only as far as $_SERVER and think that the
> [ character starts regular text. This also works with object properties
> and method return values:
>
> echo "{$some_obect->some_value} and {$some_object->some_method()}";
Um, not exactly. "This will parse correctly: $_SERVER[DOCUMENT_ROOT]."
You just can't use single quotes inside the brackets to denote the array
index, when the whole string is surrounded by double quotes. A more
pedestrian example:
$message = "The value of foo is $_POST[bar]\n";
You are, however, right about object properties. I know of no other way
to parse them inside a quoted string, other than using braces.
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
is so much more readable in any editor that does syntax highlighting,
and parses quicker too.
On Thu, Mar 11, 2010 at 1:15 AM, David Mehler wrote:
> Hello,
> I've got what is probably a very simple question, probably something
> having to do with quotes single vs. double, but the answer is
> frustrating elusive, I keep getting a syntax error.
> I'm trying to customize a wordpress theme a friend sent me. We're both
> using apache as web server and php5, but his has got to be configed
> differently than mine. The theme deals with multiple stylesheet
> inclusion among other things. The original line is:
>
> $styleSheets[0]["sheet"]='
> href="/wp-content/themes/theme/style/white.css" rel="stylesheet"
> type="text/css" />';
>
> That code puts the
> issue is his / is not where mine is, i'm using a virtual host and need
> a line similar to this:
>
> $styleSheets[0]["sheet"]='
> "/wp-content/themes/theme/style/white.css" rel="stylesheet"
> type="text/css" />';
>
> I've tried this with both double quotes before the
> but keep getting a parse error.
> Help appreciated.
> Thanks.
> Dave.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
On Thu, 2010-03-11 at 08:03 +0100, Rene Veerman wrote:
> $var = 'bla'.$var2.'doh'.$var3['index'].'argh'.$var4[$var4index];
>
> is so much more readable in any editor that does syntax highlighting,
> and parses quicker too.
>
> On Thu, Mar 11, 2010 at 1:15 AM, David Mehler wrote:
> > Hello,
> > I've got what is probably a very simple question, probably something
> > having to do with quotes single vs. double, but the answer is
> > frustrating elusive, I keep getting a syntax error.
> > I'm trying to customize a wordpress theme a friend sent me. We're both
> > using apache as web server and php5, but his has got to be configed
> > differently than mine. The theme deals with multiple stylesheet
> > inclusion among other things. The original line is:
> >
> > $styleSheets[0]["sheet"]='
> > href="/wp-content/themes/theme/style/white.css" rel="stylesheet"
> > type="text/css" />';
> >
> > That code puts the
> > issue is his / is not where mine is, i'm using a virtual host and need
> > a line similar to this:
> >
> > $styleSheets[0]["sheet"]='
> > "/wp-content/themes/theme/style/white.css" rel="stylesheet"
> > type="text/css" />';
> >
> > I've tried this with both double quotes before the
> > but keep getting a parse error.
> > Help appreciated.
> > Thanks.
> > Dave.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
Good catch Paul with the quotes around the array element!
My editor highlights those strings even without me having to keep
breaking out with concatenation Rene